﻿@page "/webhook"
@inherits AdminCompontentBase

<PageTitle>
    @T("Client")
</PageTitle>

<DefaultCard>
    <AutoHeight>
        <HeaderContent>
            <div class="d-flex mb-6">
                <SSearch @bind-Value="_getWebhookPaginationDto.Name" OnEnter="SearchKeyHandler" />
                <MSpacer />
                <SButton Small OnClick="()=>_addDialog.ShowAsync(Guid.Empty)" BorderRadiusClass="rounded-lg">
                     <SIcon Size=18 IsDefaultToolTip="false">@IconConstants.Add</SIcon>
                        <span class="ml-2 btn">@T("Add")</span>
                </SButton>
            </div>
        </HeaderContent>
        <AutoHeightContent>
            <SDataTable Height="@("calc(100vh - 288px)")"
                        Headers="_headers"
                        Items="_paginationDto.Items"
                        TItem="WebhookItemDto"
                        ItemsPerPage="_getWebhookPaginationDto.PageSize">

                <HeaderColContent Context="header">
                    <span>@header.Text</span>
                </HeaderColContent>
                <ItemColContent>
                    @switch (context.Header.Value)
                    {
                        case nameof(WebhookItemDto.IsActive):
                            <EnableChip Value=context.Item.IsActive />
                            break;
                        case "Action":
                            <div class="d-flex justify-center">
                                <MButton Class="mr-4" Icon OnClick="()=>OpenUpdateDialog(context.Item.Id)">
                                     <SIcon Tooltip="@T("Edit")" Size="20" Color="regular">@IconConstants.Update</SIcon>
                                    </MButton>
                                    <MButton Class="mr-4" Icon OnClick="()=> OpenRemoveDialog(context.Item)">
                                     <SIcon Tooltip="@T("Delete")">@IconConstants.Remove</SIcon>
                                </MButton>
                            </div>
                            break;
                        default:
                            <span>@context.Value</span>
                            break;
                    }
                </ItemColContent>
            </SDataTable>
        </AutoHeightContent>
        <FooterContent>
            <SPagination Class="mt-4" Page="_getWebhookPaginationDto.Page" PageSize=_getWebhookPaginationDto.PageSize
                         Total=_paginationDto.Total PageChanged="PageChangedHandler" PageSizeChanged="PageSizeChangedHandler" />
        </FooterContent>
    </AutoHeight>
</DefaultCard>

<AddDialog @ref="_addDialog" OnSubmitSuccess="LoadData" />